package com.hq.service;

import com.hq.bean.House;
import com.hq.bean.User;
import com.hq.dao.HouDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HouServiceImpl implements HouService {
    @Resource
    HouDao houDao;

    @Override
    public List list(String hname, String haddress) {
        return houDao.list(hname,haddress);
    }

    @Override
    public List findallowner() {
        return houDao.findallowner();
    }

    @Override
    public int addhouse(House house, String oids) {
        int i = houDao.addhouse(house);
        String[] split = oids.split(",");
        for (String s : split) {
            houDao.addho(s,house.getHid());
        }
        return i;
    }

    @Override
    public User login(User user) {
        return houDao.login(user);
    }

    @Override
    public House findhouse(Integer id) {
        return houDao.findhouse(id);
    }

    @Override
    public int updhouse(House house, String oids) {
        houDao.delid(String.valueOf(house.getHid()));
        int updhouse = houDao.updhouse(house);
        String[] split = oids.split(",");
        for (String s : split) {
            houDao.addho(s,house.getHid());
        }
        return updhouse;
    }
}
